package com.floreantpos.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

import net.sf.jasperreports.engine.JRException;
import net.sf.jasperreports.engine.JasperCompileManager;

public class Util {

	public static String formatDateTime(Date d) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		return sdf.format(d);
	}

	public static String formatDate(Date d) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		return sdf.format(d);
	}

	public static Date parseDateTime(String d) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		try {
			return sdf.parse(d);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static Date parseDate(String d) {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		try {
			return sdf.parse(d);
		} catch (ParseException e) {
			e.printStackTrace();
		}
		return null;
	}

	public static String getDate(String date,int days)  
	{
		Date d = parseDate(date);
		SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");  
	    Calendar calendar = Calendar.getInstance();
	    calendar.setTime(d);
	    calendar.set(Calendar.DAY_OF_YEAR,calendar.get(Calendar.DAY_OF_YEAR) + days);
	    return df.format(calendar.getTime());
	}
	
	public static void main(String[] args) {
		System.out.println(Util.parseDateTime(
				Util.formatDate(new Date()) + " 23:59:59").after(
				Util.parseDateTime(Util.formatDate(new Date()) + " 00:00:00")));
	}
}
